﻿using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Routing;

namespace WebIG.Service
{
    public class Utility
    {
        public static string HttpPost(string url, NameValueCollection postData, params object[] args)
        {
            var webClient = new WebClient();
            webClient.Proxy = GetProxy();

            var result = webClient.UploadValues(string.Format(url, args), postData);

            var response = Encoding.Default.GetString(result);

            return response;
        }

        public static string HttpGet(string url, params object[] args)
        {
            var request = WebRequest.Create(string.Format(url, args)) as HttpWebRequest;
            request.Proxy = GetProxy();

            var response = request.GetResponse() as HttpWebResponse;

            using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                return reader.ReadToEnd();
            }
        }

        public static string HttpRequest(string url, HttpMethod method = HttpMethod.GET, params object[] args)
        {
            var request = WebRequest.Create(string.Format(url, args)) as HttpWebRequest;
            request.Proxy = GetProxy();

            request.Method = method.ToString();

            var response = request.GetResponse() as HttpWebResponse;

            using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                return reader.ReadToEnd();
            }
        }

        private static WebProxy GetProxy()
        {
            return null;
        }
    }

    public enum HttpMethod
    {
        GET,
        POST,
        DELETE,
        PUT,
    }
}